package com.example.android2019.ch5broadcast;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.android2019.R;

public class BroadActivity extends AppCompatActivity {
    Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad);
        btn1 = findViewById(R.id.btn_broad_my_one);
        btn2 = findViewById(R.id.btn_broad_my_two);

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.btn_broad_my_one:
                        /*跳转*/
                        Intent intent = new Intent(BroadActivity.this, BroadcastActivity.class);
                        /*传递数据*/
                        intent.putExtra("test", "tz");
                        startActivity(intent);
                        break;
                    case R.id.btn_broad_my_two:
                        /*跳转*/
                        Intent intent1 = new Intent(BroadActivity.this, HelpActivity.class);
                        /*传递数据*/
                        intent1.putExtra("test", "tz");
                        startActivity(intent1);
                        break;
                }
            }
        };
        btn1.setOnClickListener(listener);
        btn2.setOnClickListener(listener);

        /*获取传递的数据*/
        Intent intent = this.getIntent();
        String a = intent.getStringExtra("test");
        Toast.makeText(this, a, Toast.LENGTH_SHORT).show();
    }
}
